require(["jquery",'public','weui'],function($,public,weui) {
    //public.headertitle('我收藏的');
    public.footer(1);
    public.allocator();

    function getData(){
        $.ajax({
            type: 'post',
            dataType: 'json',
            data: {token: public.getSession('token')},
            url: MODULE+'Goods/college_list',           
        }).success(function (res) {
            console.log(res);   
            var _html = '';
            if(!res.data || !res.data.length){
            	$('.products_main').addClass('myFav_none');
            	return false;
            }
            res.data.forEach(function(i){
                _html += '<dl class="products_item">'
					+		'<dt class="products_item_shopInfo">'
					+		'</dt>'
					+		'<dd>'
					+			'<a class="products_item_productInfo_link" href="'+MODULE+'PublicJump/productInfo/id/'+i.child[0].goods_id+'">'
					+				'<div class="products_item_productInfo">'
					+					'<div class="img_box">'
					+						'<img src="'+PUBLIC+i.child[0].goods_picture_path+'" />'
					+					'</div>'
					+					'<div class="text_box">'
					+						'<p>'+i.child[0].goods_main+'</p>'
					+						'<span>￥'+i.child[0].goods_price+'</span>'
					+					'</div>'
					+				'</div>'
					+			'</a>'
					+			'<div class="products_item_btnset" data-id="'+i.child[0].goods_id+'">'
					+				'<a class="bx4 delete" href="javascript:void(0);">删除</a>'
					+			'</div>'
					+		'</dd>'
					+	'</dl>'; 
            });
            $('.products_main').append(_html);
        }).fail(function (jqXHR, textStatus, errorThrown) {});
    }

    getData();

    //页面加载完毕
    public.loaded();

    //删除
    $('.products_main').on('click','.delete',function(event){
    	var $this = $(this);
    	if($this.hasClass('on')){
    		return false;
    	}
    	$this.addClass('on');
    	var id = $this.closest('.products_item_btnset').data('id');
    	$.ajax({
            type: 'post',
            dataType: 'json',
            data: {id: id,token: public.getSession('token')},
            url: MODULE+'Goods/delete_college',           
        }).success(function (res) {
        	if(res.code == 0){
            	$.alert('删除成功',function(){
            		$this.closest('.products_item').remove();
            	});            	
            }else{
            	$.alert('删除失败');
            }
            $this.removeClass('on');
        }).fail(function (jqXHR, textStatus, errorThrown) {});
    });
})